package com.xzx.paymentdemo.controller;

import com.xzx.paymentdemo.entity.Product;
import com.xzx.paymentdemo.service.ProductService;
import com.xzx.paymentdemo.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 商品
 *
 * @author xzx
 * @since 2022/5/29
 */

@CrossOrigin//开放前端的跨域访问
@Api(tags = "商品管理")
@RestController
@RequestMapping("/api/product")
public class productController {

    @Autowired
    private ProductService productService;

    @ApiOperation("测试接口")
    @GetMapping("/test")
    public R test() {
//        return R.success("成功", (Map<String, Object>) new HashMap<>().put("now", new Date()));
        return R.ok().data("message", "hello").data("now", new Date());
    }

    @ApiOperation("获取商品列表")
    @GetMapping("/list")
    public R getProducts() {
        List<Product> products = productService.list();
        return R.ok().data("productList", products);
    }
}
